package com.example.chongwushangcheng;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.example.petshopping.R;

public class PublishActivity extends AppCompatActivity {

    private ImageButton btnBack;
    private ImageView imagePreview1;
    private ImageView imagePreview2;
    private FrameLayout imageUploadBtn;
    private EditText titleInput;
    private EditText contentInput;
    private ConstraintLayout locationContainer;
    private Button publishBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publish);

        // 初始化视图
        initViews();
        // 设置监听器
        setupListeners();
    }

    private void initViews() {
        btnBack = findViewById(R.id.btn_back);
        imagePreview1 = findViewById(R.id.image_preview_1);
        imagePreview2 = findViewById(R.id.image_preview_2);
        imageUploadBtn = findViewById(R.id.image_upload_btn);
        titleInput = findViewById(R.id.title_input);
        contentInput = findViewById(R.id.content_input);
        locationContainer = findViewById(R.id.location_container);
        publishBtn = findViewById(R.id.publish_btn);
    }

    private void setupListeners() {
        // 返回按钮点击事件
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        // 图片上传按钮点击事件
        imageUploadBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 这里应该调用选择图片的方法
                Toast.makeText(PublishActivity.this, "上传图片功能", Toast.LENGTH_SHORT).show();
            }
        });

        // 位置选择点击事件
        locationContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 这里应该跳转到位置选择页面
                Toast.makeText(PublishActivity.this, "选择位置功能", Toast.LENGTH_SHORT).show();
            }
        });

        // 发布按钮点击事件
        publishBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String title = titleInput.getText().toString().trim();
                String content = contentInput.getText().toString().trim();

                if (title.isEmpty()) {
                    Toast.makeText(PublishActivity.this, "请添加标题", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (content.isEmpty()) {
                    Toast.makeText(PublishActivity.this, "请添加正文", Toast.LENGTH_SHORT).show();
                    return;
                }

                // 这里应该处理发布逻辑
                Toast.makeText(PublishActivity.this, "发布成功", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }
} 